const app = getApp();
const Bmob = require("../../utils/bmob.js");
const util = require('../../utils/util.js');
var that;
Page({
  data: {
    isLogin: false,
    userPic: wx.getStorageSync('my_avatar'),
    nickName: wx.getStorageSync('my_nick'),
    buttonClicked: false, //是否点击跳转
  },
  onLoad() {

  },
  onShow() {
    var that = this
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          that.setData({
            isLogin: false,
            userPic: wx.getStorageSync('my_avatar'),
            nickName: wx.getStorageSync('my_nick')
          })
          console.log("if getset", res, "已授权状态")
        } else {
          that.setData({
            isLogin: true
          })
          console.log("else getset", "未授权状态")
        }
      }
    })
  },
  getUserInfo() {
    app.onLaunch()
    this.onLoad()
    setTimeout(() => {
      this.onShow()
    }, 2000)
  },
  goLuanch: function () {
    that = this
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          if (!that.buttonClicked) {
            util.buttonClicked(that);
            wx.navigateTo({
              url: '/pages/my/mylaunch/mylaunch',
            })
          }
          console.log("if getset", res, "已授权状态")
        } else {
          wx.showModal({
            showCancel: false,
            content: '请先登录',
          })
        }
      }
    })
  },
  goJoin: function () {
    that = this
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          if (!that.buttonClicked) {
            util.buttonClicked(that);
            wx.navigateTo({
              url: '/pages/my/myjoin/myjoin',
            })
          }
          console.log("if getset", res, "已授权状态")
        } else {
          wx.showModal({
            showCancel: false,
            content: '请先登录',
          })
        }
      }
    })
  },
  goCollect: function () {
    that = this
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          if (!that.buttonClicked) {
            util.buttonClicked(that);
            wx.navigateTo({
              url: '/pages/my/mycollection/mycollection',
            })
          }
          console.log("if getset", res, "已授权状态")
        } else {
          wx.showModal({
            showCancel: false,
            content: '请先登录',
          })
        }
      }
    })
  },
  goAbout: function () {
    if (!this.buttonClicked) {
      util.buttonClicked(this);
      wx.navigateTo({
        url: '/pages/my/projectbrief/projectbrief',
      })
    }
  },
  goDynamic: function () {
    if (!this.buttonClicked) {
      util.buttonClicked(this);
      wx.navigateTo({
        url: '/pages/my/myDynamic/myDynamic',
      })
    }
  }
})